<?php
include("global.php");

$links=" > CVS";
$pagetitle=" - CVS";

include("header.php");

if($configarray[40]){
	unset($tplcontent);
	$tplcontent['notice'].="<b>Board closed:</b><br>$configarray[40]";
	echo template('notice',$tplcontent);
}else{
	
	if($login!==1){
		unset($tplcontent);
		$tplcontent['notice'].="Must be logged in to access this section";
		echo template('notice',$tplcontent);
	}else{
		
		$filesarray[0][0]="";
		$filesarray[0][1]=listfilesext(".");
		
		$filesarray[1][0]="languages/english/";
		$filesarray[1][1][0]="definition.php";
		
		$filesarray[2][0]="modules/members/";
		$filesarray[2][1]=listfilesext("modules/members");
		
		$filesarray[3][0]="modules/search/";
		$filesarray[3][1]=listfilesext("modules/search");
		
		$filesarray[4][0]="replacements/navboard/english/";
		$filesarray[4][1]=listfilesext("replacements/navboard/english");
		
		$filesarray[5][0]="templates/navboard/english/";
		$filesarray[5][1]=listfilesext("templates/navboard/english");
		
		$filesarray[6][0]="templates/navboard/english/modules/members/";
		$filesarray[6][1]=listfilesext("templates/navboard/english/modules/members");
		
		$filesarray[7][0]="templates/navboard/english/modules/search/";
		$filesarray[7][1]=listfilesext("templates/navboard/english/modules/search");
		
		$filesarray[8][0]="themes/navboard/english/";
		$filesarray[8][1]=listfilesext("themes/navboard/english");
		
		$filesarray[8][0]="themes/navboard/";
		$filesarray[8][1]=listfilesext("themes/navboard");
		
		if($step==""){
			
			unset($tplcontent);
			$tplcontent['formheader'].="<form action=\"cvs.php\" method=\"post\">";
			$tplcontent['formheader'].="<input type=hidden name=\"step\" value=\"2\">";
			$tplcontent['formheader'].="<input type=hidden name=\"file\" value=\"$file\">";
			
			if($file==""){$file="index.php";}
			
			$tplcontent['files'].="<select name=\"file\" class=\"forminput\" onchange=\"window.location='cvs.php?file='+(this.options[this.selectedIndex].value)\">";
			
			for($n=0;$n<count($filesarray);$n++){
				for($m=0;$m<count($filesarray[$n][1]);$m++){
					$tplcontent['files'].="<option value=\"".$filesarray[$n][0].$filesarray[$n][1][$m]."\" ";
					if(($filesarray[$n][0].$filesarray[$n][1][$m])==$file){
						$tplcontent['files'].="selected";
						$codearray=file($file);
					}
					$tplcontent['files'].=">".$filesarray[$n][0].$filesarray[$n][1][$m]."</option>";
				}
			}
			
			if(count($codearray)<=0){
				$file="index.php";
				$codearray=file($file);		
			}
			
			$tplcontent['files'].="</select>";
			
			$tplcontent['filename'].=$file;
			
			$tplcontent['time']=date($dateformat,filemtime($file));
			
			$tplcontent['fullcode'].="<textarea cols=150 rows=50 name=\"fullcode\" size=30 class=\"forminput\" wrap=off>";
			
			for($n=0;$n<count($codearray);$n++){
				$tplcontent['fullcode'].=htmlentities(stripslashes($codearray[$n]));
			}
			
			$tplcontent['fullcode'].="</textarea>";
			
			$tplcontent['copy'].="<textarea cols=150 rows=30 name=\"copy\" size=30 class=\"forminput\" wrap=off></textarea>";
			$tplcontent['changed'].="<textarea cols=150 rows=30 name=\"changed\" size=30 class=\"forminput\" wrap=off></textarea>";
			$tplcontent['description'].="<textarea cols=100 rows=20 name=\"description\" size=30 class=\"forminput\"></textarea>";
			
			$tplcontent[submitbutton].="<input type=submit name=\"submit\" value=\"Submit!\" class=\"formbutton\">";
			
			$tplcontent['formfooter'].="</form>";
			
			echo template('cvs',$tplcontent);
		}
		
		if($step==2){
			$forum=15;
			
			$topictime=time();
			
			createdir("$configarray[2]/$forum/$topictime");
			
			$topicidarray=getdata("$configarray[2]/".$forum."_topics.php");
			$topicnum=count($topicidarray);
			writedata("$configarray[2]/".$forum."_topics.php",$topictime,$topicnum);
			writedata("$configarray[2]/$forum/$topictime.php",$topicnum,3);
			
			writedata("$configarray[2]/$forum/$topictime/0.php",$useridarray[$navboardlogin],0);
			writedata("$configarray[2]/$forum/$topictime/0.php",$time,1);
			writedata("$configarray[2]/$forum/$topictime/0.php","Code submission - ".$file." - #".$topicnum." - ".date($dateformat,$topictime),2);
			
			$body="Original code[br][code]".$copy."[/code][br][br]Changed code[br][code]".$changed."[/code][br][br]Description[br][code]".$description."[/code]";
			$body=ereg_replace("\n","",$body);
			$body=ereg_replace("\r","[br]",$body);
			$body=stripslashes($body);
			
			writedata("$configarray[2]/$forum/$topictime/0.php",$body,3);
			writedata("$configarray[2]/$forum/$topictime/0.php",$REMOTE_ADDR,9);
			
			$tplcontent['notice'].="Code submitted, auto redirecting to topic";
			
			echo template('notice',$tplcontent);
			
			echo "<meta http-equiv=\"refresh\" content=\"2; url=index.php?forum=$forum&topic=$topicnum\">";
		}//step 2 bracket
		
	}//logged in check
	
}//board closed check

require ("footer.php");
?>
